package com.hehe.Config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Currency;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    /*
     * 图片保存路径，自动从yml文件中获取数据
     *   示例： E:/images/
     */
    @Value("${file.upload.path}")
    private String fileSavePath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /*
         * 配置资源映射
         * 意思是：如果访问的资源路径是以“/images/”开头的，
         * 就给我映射到本机的“E:/images/”这个文件夹内，去找你要的资源
         * 注意：E:/images/ 后面的 “/”一定要带上
         * 浏览器访问图片 : http://192.168.1.6:8088/aaaimages/aaa.png
         */
        System.out.println("application-dev.properties  : fileSavePath = " + fileSavePath);

        String currentDirectory = System.getProperty("user.dir");
        System.out.println("当前目录路径：" + currentDirectory);  // 当前目录路径：C:\Users\yxb\Desktop\SQL_STUDY

        currentDirectory = currentDirectory + "\\" + "SQL_IMG\\";
        System.out.println("currentDirectory = " + currentDirectory);

        registry.addResourceHandler("/SQL_IMG/**").addResourceLocations("file:"+currentDirectory);
    }
}
